#include "AccountManager.h"

AccountManager::AccountManager()
{
	//ctor
}

AccountManager::~AccountManager()
{
	//dtor
}


// 是否注册过
bool AccountManager::isRigster(string _user)
{
	// 查看内存中有没有
	map<int, Account>::iterator Iter;
	for(Iter = m_AccountMap.begin(); Iter != m_AccountMap.end(); Iter++)
	{
		Account TAccont = Iter->second;
		if(TAccont.m_user == _user)
			return true;
	}

	return false;
}

// 账户验证
// return
// 		0:成功
// 		1:密码错误
//  	2:没有该帐号
int AccountManager::Verification(string _user, string _pwd, int& _userId)
{
	map<int, Account>::iterator Iter;
	for(Iter = m_AccountMap.begin(); Iter != m_AccountMap.end(); Iter++)
	{
		Account TAccont = Iter->second;
		if(TAccont.m_user != _user)
			continue;

		if(Iter->second.m_pwd != _pwd)
			return 1;

		_userId = Iter->second.m_uid;
		return 0;
	}

	return 2;
}

bool AccountManager::Cache(const tUser& _DB)
{

	if(m_AccountMap.count(_DB.id)> 0)
	{
		Debug::Error(__func__ , " Alreay in Cache _DB.id:", _DB.id);
		return false;
	}

	Account Data;
	Data.m_uid = _DB.id;
	Data.m_user = _DB.user;
	Data.m_pwd = _DB.pwd;

	m_AccountMap[_DB.id] = Data;
	return true;
}

